package com.example.lib_net.interceptor

import okhttp3.CacheControl
import okhttp3.Interceptor
import okhttp3.Response
import java.util.concurrent.TimeUnit

/**
 * @author yaotianxue
 * @description 因为通过addNetWorkInterceptor发生网络请求之后，这样就会缓存数据
 * @date 2024/10/24
 */
class ResponseCacheInterceptor: Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val response: Response = chain.proceed(chain.request())
        val cacheControl = CacheControl.Builder()
            .maxAge(120, TimeUnit.SECONDS)
            .build()
        return response.newBuilder()
            .header("Cache-Control", cacheControl.toString())
            .build()
    }
}
